package main

import (
	"fmt"

	"github.com/apache/arrow/go/v6/arrow/array"
	"github.com/apache/arrow/go/v6/arrow/memory"
)

func printArrow(values []int64, validity []bool) {
	fb := array.NewInt64Builder(memory.DefaultAllocator)
	fb.AppendValues(values, validity)

	vec := fb.NewInt64Array()
	for _, val := range vec.Int64Values() {
		fmt.Printf("%d\t", val)
	}

	fmt.Printf("\n--------------------------------------------------------------------------------------------\n")

	// sum := math.Int64.Sum(vec)
	// fmt.Printf("sum = %d\n", sum)

	fmt.Printf("int_array rows: %d\n", vec.Len())

	null_bm := vec.NullBitmapBytes()
	data := vec.Data()

	fmt.Printf("nullbitmap type: %T length: %d \t %b\n", null_bm, len(null_bm), null_bm)
	fmt.Printf("nullbitmap type: %T length: %d \t %b\n", data.Buffers()[0].Bytes(), len(data.Buffers()[0].Bytes()), data.Buffers()[0].Bytes())

	fmt.Printf("data_type: %d\t data Buffers: %d\n", int(data.DataType().ID()), len(data.Buffers()))

	bytes := data.Buffers()[1].Bytes()
	fmt.Printf("data type: %T length:%d \t %b\n", bytes, len(bytes), bytes)
}

func main() {
	// values := []int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}
	// validity := []bool{true, false, true, true, true, true, false, true, true, true, false, true, true, true}
	values := []int64{1, 2, 3, 4, 5, 6, 7, 8}
	validity := []bool{true, true, true, true, true, true, true, true}
	printArrow(values, validity)
}

/*

1	2	3	4	5	6	7	8
--------------------------------------------------------------------------------------------
sum = 36
int_array rows 8
nullbitmap length:4 	 [11111111 0 0 0]
data_type: 9	 data Buffers:2
data length:64 	 [1 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 11 0 0 0 0 0 0 0 100 0 0 0 0 0 0 0 101 0 0 0 0 0 0 0 110 0 0 0 0 0 0 0 111 0 0 0 0 0 0 0 1000 0 0 0 0 0 0 0]


--有空值

1	2	3	0	5	6	7	8
--------------------------------------------------------------------------------------------
sum = 32
int_array rows 8
nullbitmap length:4 	 [11110111 0 0 0]
data_type: 9	 data Buffers:2
data length:64 	 [1 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 101 0 0 0 0 0 0 0 110 0 0 0 0 0 0 0 111 0 0 0 0 0 0 0 1000 0 0 0 0 0 0 0]

*/
